{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load l10n %}
{% load eventurl %}
{% load money %}
{% load thumb %}
{% load eventsignal %}
{% load rich_text %}
{% load compress %}
{% load static %}

{% block custom_header %}
    {{ block.super }}
    <meta property="og:title" content="{{ ev.name }}" />
    <meta property="og:description" content="{{ ev.get_date_range_display }}" />
    {% if subevent %}
        <meta property="og:url" content="{% abseventurl request.event "presale:event.index" subevent=subevent.pk %}" />
    {% else %}
        <meta property="og:url" content="{% abseventurl request.event "presale:event.index" %}" />
    {% endif %}
    {% compress js %}
        <script type="text/javascript" src="{% static "pretixpresale/js/ui/join-video-event.js" %}"></script>
    {% endcompress %}
	{# Needed by popover.js #}
    {{ base_path|json_script:"base_path" }}
    {{ ev.organizer.slug|json_script:"organizer_name" }}
    {{ ev.slug|json_script:"event_slug" }}
{% endblock %}
{% block content %}

    {% autoescape off %}
        <script type="application/ld+json">
            {{ ev.event_microdata }}
        </script>
    {% endautoescape %}
    <main aria-label="{% if show_cart %}{% trans "Your cart, general information, add products to your cart" %}{% else %}{% trans "General information, add products to your cart" %}{% endif %}">
        <nav id="schedule-nav"{% if with_margin %} class="p-3"{% endif %}>
            <div class="navigation">
                {% if request.event.settings.talk_schedule_public %}
                    <div class="navigation-button">
                        <a href="{{ request.event.talk_schedule_url }}" class="header-nav btn btn-outline-success">
                            <i class="fa fa-calendar"></i> {% trans "Schedule" %}
                        </a>
                    </div>
                    <div class="navigation-button">
                        <a href="{{ request.event.talk_session_url }}" class="header-nav btn btn-outline-success">
                            <i class="fa fa-comments-o"></i> {% trans "Sessions" %}
                        </a>
                    </div>
                    <div class="navigation-button">
                        <a href="{{ request.event.talk_speaker_url }}" class="header-nav btn btn-outline-success">
                            <i class="fa fa-group"></i> {% trans "Speakers" %}
                        </a>
                    </div>
                {% endif %}
                <div class="navigation-button">
                    <a target="_blank" class="header-nav btn btn-outline-success" data-toggle="popover">
                        <i class="fa fa-ticket"></i> {% trans "Tickets" %}
                    </a>
                </div>
                {% if is_video_plugin_enabled %}
                    <div class="video-link">
                        <a join-event-link class="header-nav btn btn-outline-success join-event"
                            href='{% eventurl request.event "presale:event.onlinevideo.join" %}'>
                            <i class="fa fa-video-camera"></i> {% trans "Join online event" %}
                        </a>
                    </div>
                {% endif %}
            </div>
        </nav>
    {% if show_cart %}
        <details class="panel panel-primary cart" open>
            <summary class="panel-heading">
                <h3 class="panel-title">
                    <span>
                        <i class="fa fa-shopping-cart" aria-hidden="true"></i>
                        <strong>{% trans "Your cart" %}</strong>
                    </span>
                    <span>
                        <strong id="cart-deadline-short" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}" aria-hidden="true">
                            {% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
                                {{ cart.minutes_left|stringformat:"02d" }}:{{ cart.seconds_left|stringformat:"02d" }}
                            {% else %}
                                {% trans "Cart expired" %}
                            {% endif %}
                        </strong>
                        <i class="fa fa-angle-down collapse-indicator" aria-hidden="true"></i>
                    </span>
                </h3>
            </summary>
            <div>
                <div class="panel-body">
                    {% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
                    <em id="cart-deadline" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}">
                        {% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
                            {% blocktrans trimmed with minutes=cart.minutes_left %}
                                The items in your cart are reserved for you for {{ minutes }} minutes.
                            {% endblocktrans %}
                        {% else %}
                            {% trans "The items in your cart are no longer reserved for you." %}
                        {% endif %}
                    </em>
                    <div class="row checkout-button-row">
                        <div class="col-md-4 col-sm-6 col-xs-12 hidden-xs">
                            <form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.clear" cart_namespace=cart_namespace %}">
                                {% csrf_token %}
                                <button class="btn btn-block btn-default btn-lg" type="submit">
                                    <i class="fa fa-close" aria-hidden="true"></i> {% trans "Empty cart" %}</button>
                            </form>
                        </div>
                        <div class="col-md-4 col-sm-6 col-md-offset-4 col-xs-12">
                            {% if guest_checkout_allowed or request.user.is_authenticated %}
                                <a class="btn btn-block btn-primary btn-lg" href="{% eventurl request.event 'presale:event.checkout.start' cart_namespace=cart_namespace %}">
                                    Checkout
                                </a>
                            {% else %}
                                <a class="btn btn-block btn-primary btn-lg disabled" href="#">
                                    Checkout
                                </a>
                            {% endif %}
                        </div>
                        <div class="visible-xs-block col-xs-12">
                            <form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.clear" cart_namespace=cart_namespace %}">
                                {% csrf_token %}
                                <button class="btn btn-block btn-default btn-lg" type="submit">
                                    <i class="fa fa-close" aria-hidden="true"></i> {% trans "Empty cart" %}</button>
                            </form>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </details>
    {% endif %}

    {% if request.event.has_subevents %}
        {% if not subevent %}
            {% if event_logo_image and request.event.settings.logo_show_title %}
                <h2 class="content-header">
                    {{ event.name }}
                </h2>
            {% endif %}
            {% if frontpage_text and not cart_namespace %}
                <div>
                    {{ frontpage_text|rich_text }}
                </div>
            {% endif %}

            {% if request.GET.voucher %}
                <div class="alert alert-info">
                    {% trans "Please select a date to redeem your voucher." %}
                </div>
            {% endif %}
        {% endif %}

        {% if subevent and "year" not in request.GET %}
            {% if show_cart %}
                <a class="subevent-toggle btn btn-primary btn-block btn-lg" href="#subevent-list">
                    <span class="fa fa-reply" aria-hidden="true"></span>
                    {% trans "Add tickets for a different date" %}
                </a>
            {% else %}
                <a class="subevent-toggle btn btn-default btn-block" href="#subevent-list">
                    {% trans "View other date" %}
                </a>
            {% endif %}
        {% else %}
            <h3>{% trans "Choose date to book a ticket" %}</h3>
        {% endif %}
        <div class="panel panel-default subevent-list" id="subevent-list">
            <div class="panel-heading">
                {% if subevent %}
                    {% trans "Other dates" context "subevent" %}
                {% else %}
                    {% trans "Dates" context "subevent" %}
                {% endif %}
            </div>
            <div class="panel-body">
                <div>
                    {% if list_type == "calendar" %}
                        {% include "pretixpresale/event/fragment_subevent_calendar.html" %}
                    {% elif list_type == "week" %}
                        {% include "pretixpresale/event/fragment_subevent_calendar_week.html" %}
                    {% else %}
                        {% include "pretixpresale/event/fragment_subevent_list.html" %}
                    {% endif %}
                </div>
            </div>
        </div>
        {% if subevent %}
            <h2 class="subevent-head">{{ subevent.name }}</h2>
            {% if frontpage_text and not cart_namespace %}
                <div>
                    {{ frontpage_text|rich_text }}
                </div>
            {% endif %}
        {% endif %}
    {% else %}
        {% if event_logo_image and request.event.settings.logo_show_title %}
            <h2 class="content-header">
                {{ event.name }}
                {% if request.event.settings.show_dates_on_frontpage %}
                    <small>{{ event.get_date_range_display }}</small>
                {% endif %}
            </h2>
        {% endif %}
        {% if not event_logo_image %}
            <h2 class="content-header">
                {{ event.name }}
                {% if request.event.settings.show_dates_on_frontpage %}
                    <small>{{ event.get_date_range_display }}</small>
                {% endif %}
            </h2>
        {% endif %}
        {% if frontpage_text and not cart_namespace %}
            <div>
                {{ frontpage_text|rich_text }}
            </div>
        {% endif %}
    {% endif %}

    {% if subevent or not event.has_subevents %}
        {% if not ev.presale_is_running %}
            <div class="alert alert-info">
                {% if ev.presale_has_ended %}
                    {% if event.settings.presale_has_ended_text %}
                        {{ event.settings.presale_has_ended_text|rich_text }}
                    {% else %}
                        {% blocktrans trimmed %}
                            The presale period for this event is over.
                        {% endblocktrans %}
                    {% endif %}
                {% elif event.settings.presale_start_show_date %}
                    {% blocktrans trimmed with date=ev.effective_presale_start|date:"SHORT_DATE_FORMAT" time=ev.effective_presale_start|time:"TIME_FORMAT" %}
                        The presale for this event will start on {{ date }} at {{ time }}.
                    {% endblocktrans %}
                {% else %}
                    {% blocktrans trimmed %}
                        The presale for this event has not yet started.
                    {% endblocktrans %}
                {% endif %}
            </div>
        {% endif %}
        {% if not cart_namespace or subevent %}
            <div>
                {% if ev.location %}
                    <div class="info-row">
                        <span class="fa fa-map-marker fa-fw" aria-hidden="true"></span>
                        <p><span class="sr-only">{% trans "Location" %}:</span>
                            {{ ev.location|linebreaksbr }}
                        </p>
                    </div>
                {% endif %}
                {% if ev.settings.show_dates_on_frontpage %}
                    <div class="info-row">
                        <span class="fa fa-clock-o fa-fw" aria-hidden="true"></span>
                        <p>
                            {{ ev.get_date_range_display }}
                            {% if event.settings.show_times %}
                                <br>
                                <span data-time="{{ ev.date_from.isoformat }}" data-timezone="{{ request.event.timezone }}">
                                    {% blocktrans trimmed with time=ev.date_from|date:"TIME_FORMAT" %}
                                        Begin: {{ time }}
                                    {% endblocktrans %}
                                </span>
                                {% if event.settings.show_date_to and ev.date_to %}
                                    <br>
                                    <span data-time="{{ ev.date_to.isoformat }}" data-timezone="{{ request.event.timezone }}">
                                        {% blocktrans trimmed with time=ev.date_to|date:"TIME_FORMAT" %}
                                            End: {{ time }}
                                        {% endblocktrans %}
                                   </span>
                                {% endif %}
                            {% endif %}
                            {% if ev.date_admission %}
                                <br>
                                {% if ev.date_admission|date:"SHORT_DATE_FORMAT" == ev.date_from|date:"SHORT_DATE_FORMAT" %}
                                    <span data-time="{{ ev.date_admission.isoformat }}" data-timezone="{{ request.event.timezone }}">
                                        {% blocktrans trimmed with time=ev.date_admission|date:"TIME_FORMAT" %}
                                            Admission: {{ time }}
                                        {% endblocktrans %}
                                    </span>
                                {% else %}
                                    <span data-time="{{ ev.date_admission.isoformat }}" data-timezone="{{ request.event.timezone }}">
                                        {% blocktrans trimmed with datetime=ev.date_admission|date:"SHORT_DATETIME_FORMAT" %}
                                            Admission: {{ datetime }}
                                        {% endblocktrans %}
                                    </span>
                                {% endif %}
                            {% endif %}
                            <br>
                            {% if subevent %}
                                <a href="{% eventurl event "presale:event.ical.download" subevent=subevent.pk %}">
                            {% else %}
                                <a href="{% eventurl event "presale:event.ical.download" %}">
                            {% endif %}
                                {% trans "Add to Calendar" %}
                            </a>
                        </p>
                    </div>
                {% endif %}

            </div>

            {% eventsignal event "eventyay.presale.signals.front_page_top" request=request subevent=subevent %}
        {% endif %}

        {% if ev.presale_is_running or event.settings.show_items_outside_presale_period %}
            <form method="post" data-asynctask
                    data-asynctask-headline="{% trans "We're now trying to reserve this for you!" %}"
                    data-asynctask-text="{% blocktrans with time=event.settings.reservation_time %}Once the items are in your cart, you will have {{ time }} minutes to complete your purchase.{% endblocktrans %}"
                    class="{% if event.seating_plan_id %}has-seating{% endif %}"
                    action="{% eventurl request.event "presale:event.cart.add" cart_namespace=cart_namespace %}?next={{ cart_redirect|urlencode }}&next_error={{ request.path|urlencode }}">
                {% csrf_token %}
                <input type="hidden" name="subevent" value="{{ subevent.id|default_if_none:"" }}" />
                {% if ev.seating_plan_id and event.settings.seating_choice %}
                    {% if event.has_subevents %}
                        {% eventsignal event "eventyay.presale.signals.render_seating_plan" request=request subevent=subevent %}
                    {% else %}
                        {% eventsignal event "eventyay.presale.signals.render_seating_plan" request=request %}
                    {% endif %}
                {% endif %}
                {% include "pretixpresale/event/fragment_product_list.html" %}
                {% if ev.presale_is_running and display_add_to_cart %}
                    <section class="front-page">
                        <div class="row-fluid">
                            <div class="col-md-4 col-md-offset-8 col-xs-12">
                                <button class="btn btn-block btn-primary btn-lg" type="submit" id="btn-add-to-cart">
                                    {% if request.event.settings.redirect_to_checkout_directly %}
                                        {% if allfree %}
                                            <i class="fa fa-check" aria-hidden="true"></i> {% trans "Register" context "free_tickets" %}
                                        {% else %}
                                           <i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Proceed with checkout" %}
                                        {% endif %}
                                    {% else %}
                                        <i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Add to cart" %}
                                    {% endif %}
                                </button>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </section>
                {% endif %}
            </form>
        {% endif %}
    {% endif %}
    </main>
    {% if show_vouchers %}
        <aside class="front-page" aria-labelledby="redeem-a-voucher">
            <h3 id="redeem-a-voucher">{% trans "Redeem a voucher" %}</h3>
            {% if event.settings.voucher_explanation_text %}
                <div>
                    {{ event.settings.voucher_explanation_text|rich_text }}
                </div>
            {% endif %}
            <form method="get" action="{% eventurl event "presale:event.redeem" cart_namespace=cart_namespace %}">
                <div class="row-voucher">
                    <div class="col-md-8 col-sm-6 col-xs-12">
                        <label for="voucher" class="sr-only">{% trans "Voucher code" %}</label>
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-ticket fa-fw" aria-hidden="true"></i></span>
                            <input type="text" class="form-control" name="voucher" id="voucher"
                                    placeholder="{% trans "Voucher code" %}">
                        </div>
                    </div>
                    <input type="hidden" name="subevent" value="{{ subevent.id|default_if_none:"" }}" />
                    <div class="col-md-4 col-sm-6 col-xs-12">
                        <button class="btn btn-block btn-primary" type="submit">
                            {% trans "Redeem voucher" %}
                        </button>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </form>
        </aside>
    {% endif %}
    {% if guest_checkout_allowed %}
        {% if not cart_namespace %}
            {% eventsignal event "eventyay.presale.signals.front_page_bottom" subevent=subevent request=request %}
            <aside class="front-page" aria-labelledby="if-you-already-ordered-a-ticket">
                <h3 id="if-you-already-ordered-a-ticket">{% trans "If you already ordered a ticket" %}</h3>
                <div>
                    <div class="col-md-8 col-xs-12">
                        <p>
                            {% blocktrans trimmed %}
                                If you want to see or change the status and details of your order, click on the link in
                                one of the
                                emails we sent you during the order process. If you cannot find the link, click on the
                                following button to request the link to your order to be sent to you again.
                            {% endblocktrans %}
                        </p>
                    </div>
                    <div class="col-md-4 col-xs-12">
                        <a class="btn btn-block btn-default" href="{% eventurl event "presale:event.resend_link" %}">
                            {% trans "Resend order links" %}
                        </a>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </aside>
        {% else %}
            {% eventsignal event "eventyay.presale.signals.front_page_bottom_widget" subevent=subevent request=request %}
        {% endif %}
    {% endif %}
{% endblock %}
